package com.ycc.springcloud.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

/**
 * 用于界面跳转的controller
 */
@Controller
public class mycontroller {

    @Autowired
    com.ycc.springcloud.service.impl.authservice authservice;
    @Autowired
    com.ycc.springcloud.service.impl.userservice userservice;
    @Autowired
    com.ycc.springcloud.service.impl.esservice esservice;


    @RequestMapping("/register")
    String register(@RequestParam("username") String username, @RequestParam("password") String password) {
        System.out.println(username+"======"+password);
        authservice.insert(username);
        userservice.insert(username,password);
        return "login";
    }
    @RequestMapping({"/","/index"})
    String index() {
        return "index";
    }
    @RequestMapping("/tologin")
    String toLogin() {
        return "login";
    }
    @RequestMapping("/developer")
    String developer() {
        return "developer";
    }
    @RequestMapping("/ourInfo")
    String ourInfo() {
        return "ourInfo";
    }
    @RequestMapping("/rose")
    String rose() {
        return "rose";
    }
    @RequestMapping("/feedback")
    String feedback() {
        return "feedback";
    }
    @RequestMapping("/userInfo")
    String userInfo(ModelMap modelMap) {
        User user =(User)
                SecurityContextHolder.getContext().getAuthentication().getPrincipal();

        List<com.ycc.springcloud.pojo.User> users = new ArrayList<>();
        com.ycc.springcloud.pojo.User user1=userservice.selectUserByUsername(user.getUsername());
        users.add(user1);

        modelMap.clear();
        modelMap.addAttribute("users",users);
        return "userInfo";
    }

}
